Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
create-error-class
Advanced tools
The 'create-error-class' npm package is a utility that allows developers to create custom error classes in JavaScript. This is particularly useful for defining specific types of errors in applications, which can enhance error handling by making it easier to identify and react to different error conditions.
Creating custom error classes
This feature allows developers to create their own error classes. The custom error can then be thrown with a specific message, making it clear what type of error occurred.
const createError = require('create-error-class');
const MyCustomError = createError('MyCustomError');
throw new MyCustomError('Something went wrong');
Similar to 'create-error-class', 'http-errors' is used to create HTTP error objects. While 'create-error-class' is generic and can be used for any type of error, 'http-errors' is specifically tailored for HTTP errors, making it more suitable for web applications.
This package also allows the creation of custom error classes. It is quite similar to 'create-error-class' but offers additional options for setting default properties on the error instances, providing slightly more flexibility.
Create error class
$ npm install --save create-error-class
var createErrorClass = require('create-error-class');
var HTTPError = createErrorClass('HTTPError', function (props) {
this.message = 'Status code is ' + props.statusCode;
});
throw new HTTPError({statusCode: 404});
Return constructor of Errors with className
.
Required
Type: string
Class name of Error Object. Should contain characters from [0-9a-zA-Z_$]
range.
Type: function
Setup function, that will be called after each Error object is created from constructor with context of Error object.
By default setup
function sets this.message
as first argument:
var MyError = createErrorClass('MyError');
new MyError('Something gone wrong!').message; // => 'Something gone wrong!'
MIT © Vsevolod Strukchinsky
FAQs
Create Error classes
We found that create-error-class demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.